/**卡片基类 */
class BaseCard extends egret.EventDispatcher implements IDisposable{
	protected ID:number
	protected cname:string
	protected crare:RareType
	protected ctype:CardType
	protected dataObj:ICardData
	protected disp:CardComponent
	/**效果 */
	protected effect
	/**使用次数 */
	public useTime:UseTime
	public player:Player
	/**放置位置, null=在手卡 */
	public tgtPlace:CardPosition
	/**当前位置, null=在手卡 */
	public curPlace:CardPosition
	protected _isFront:boolean

	public constructor(data:ICardData) {
		super()
		const t = this
		t.dataObj = data
		t.ID = data.ID
		t.cname = data.name
		t.crare = data.rare
		t.ctype = data.cty
		t.disp = new CardComponent(t)
		t._isFront = true
	}

	public finishMoving(){
		this.curPlace = this.tgtPlace
		this.tgtPlace = null
	}

	public moveTo(p:CardPosition){
		this.tgtPlace = p
	}

	public remove(){
		this.tgtPlace = null
	}

	public get name(){
		return this.cname
	}
	/**罕贵 */
	public get rare(){
		return this.crare
	}

	/**卡盘类型 */
	public get type(){
		return this.ctype
	}

	/**显示对象 */
	public get display(){
		return this.disp
	}

	/**卡片配置数据 */
	public get oriData(){
		return this.dataObj
	}
	/**是否表侧显示 */
	public set isFront(v:boolean){
		this._isFront = v
		if(this.disp) this.disp.isFront = v
	}
	/**是否表侧显示 */
	public get isFront(){
		return this._isFront
	}

	public dispose(){

	}
}


class UseTime {
	protected cur:number
	protected max:number
	protected ty:UseType
	public constructor(t:number, ty:'e'|'t'){
		this.max = t
		this.cur = t
		switch(ty){
			case 'e':
				this.ty = UseType.EFFECT
				break
			case 't':
				this.ty = UseType.TURN
				break
		}
	}

	public get isActive(){
		return this.cur > 0
	}

	public onEffect(){
		if(this.ty == UseType.EFFECT && this.cur > 0){
			this.cur --
		}
	}
	
	public onTurnPassed(){
		if(this.ty == UseType.TURN && this.cur > 0){
			this.cur --
		}
	}

	public get currentTime(){
		return this.cur
	}

	public get maxTime(){
		return this.max
	}

	public get type(){
		return this.ty
	}
}
